package cc.wanforme.fsync.server.service.impl;

import cc.wanforme.fsync.entity.po.GroupMap;
import cc.wanforme.fsync.server.mapper.GroupMapMapper;
import cc.wanforme.fsync.server.service.IGroupMapService;
import cc.wanforme.st.server.util.AssertCheck;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GroupMapServiceImpl extends ServiceImpl<GroupMapMapper, GroupMap>
        implements IGroupMapService {

    @Override
    public GroupMap saveVo(GroupMap vo) {
        AssertCheck.nonNull(vo.getName(), "miss name");
        //AssertCheck.nonNull(vo.getSourceClient(), "miss source client");
        AssertCheck.nonNull(vo.getSource(), "miss source path");
        AssertCheck.nonNull(vo.getTargetClient(), "miss target client");
        AssertCheck.nonNull(vo.getTarget(), "miss target");

        this.save(vo);
        return vo;
    }

    @Override
    public GroupMap updateVo(GroupMap vo) {
        AssertCheck.nonNull(vo.getId(), "unknown");
        AssertCheck.nonNull(vo.getName(), "miss name");
        //AssertCheck.nonNull(vo.getSourceClient(), "miss source client");
        AssertCheck.nonNull(vo.getSource(), "miss source path");
        AssertCheck.nonNull(vo.getTargetClient(), "miss target client");
        AssertCheck.nonNull(vo.getTarget(), "miss target");

        this.updateById(vo);
        return vo;
    }

    @Override
    public List<String> groups() {
        return this.baseMapper.groups();
    }

    @Override
    public List<GroupMap> listByGroups(String name) {
        return this.baseMapper.listByGroups(name);
    }
}
